<?php
class notenskala_controller extends CI_Controller {

	public function __construct()
	{
		parent::__construct();

		if($this->session->userdata('logged_in'))
   		{
			$this->load->model('notenskala_model');
		}
   		else
   		{
     		//If no session, redirect to login page
     		redirect('welcome', 'refresh');
   		}
	}
	
	public function index()
	{
		$user_data = $this->session->userdata('logged_in');
   		if($this->session->userdata('logged_in') && ($user_data['role'] == 'lehrer'))
   		{
			$data['notencode'] = $this->input->post('notencode');
			$data['notenskala'] = $this->notenskala_model->get_notenskala($data['notencode']);
			
			$data['_scripts'] = '';
		 	$data['_styles'] = '';
			$data['head'] = '';
			$data['schulname'] = 'Berufskolleg Uerdingen';
			$data['navi'] = $this->load->view('login/lehrernavi_view', $data,TRUE);
			$data['login'] = '';
			$data['content'] = $this->load->view('notenskala/notenskalaindex_view', $data,TRUE);
			$data['footer'] = $this->load->view('templates/footer', $data, TRUE);
			
			$this->load->view('MeinBKU_Template/MeinBKU_Template/template', $data);
		}
		else
	 	{
	   		//If no session, redirect to login page
	   		show_error('403 FORBIDDEN',$status_code= 403);
	 	}
	}
	
	public function notenskala_view()
	{
		$user_data = $this->session->userdata('logged_in');
   		if($this->session->userdata('logged_in') && ($user_data['role'] == 'lehrer'))
   		{
			$data['notencode'] = $this->input->post('notencode');
			$data['notenskala'] = $this->notenskala_model->get_notenskala($data['notencode']);
			
			$data['_scripts'] = '';
		 	$data['_styles'] = '';
			$data['head'] = '';
			$data['schulname'] = 'Berufskolleg Uerdingen';
			$data['navi'] = $this->load->view('login/lehrernavi_view', $data,TRUE);
			$data['login'] = '';
			$data['content'] = $this->load->view('notenskala/notenskala_view', $data,TRUE);
			$data['footer'] = $this->load->view('templates/footer', $data, TRUE);
			
			$this->load->view('MeinBKU_Template/MeinBKU_Template/template', $data);
		}
		else
	 	{
	   		//If no session, redirect to login page
	   		show_error('403 FORBIDDEN',$status_code= 403);
	 	}
	}
	
	public function set_notenskala()
	{
		$this->load->helper('form');
		$this->load->library('form_validation');
		
		#$klausurfragen['klausurenid'] = $this->input->post('klausurenid');
		$notenskala = $_POST['AbProzent'];
		
		$this->notenskala_model->delete_notenskala();
		$this->notenskala_model->set_notenskala($notenskala);	
		$this->index();
	}
}